package ch.fhnw.qualiscan.application.components;

import ch.fhnw.qualiscan.Config;
import ch.fhnw.qualiscan.application.elements.LoginFormElement;
import ch.fhnw.qualiscan.core.LayoutComponent;
import ch.fhnw.qualiscan.core.db.pojos.SurveyUserRole;

import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.CustomLayout;
import com.vaadin.ui.VerticalLayout;

import eu.livotov.tpt.i18n.TM;
/**
 * Login Box Component
 * @author Kevin Mettenberger, Benjamin Groehbiel
 *
 */
@SuppressWarnings("serial")
public class LoginFormBox extends LayoutComponent {

	private LoginFormElement login;
	public SurveyUserRole invitationSurvey;
	public boolean updateSur;

	public LoginFormBox() {}
	
	public LoginFormBox(SurveyUserRole invitationSurvey, boolean updateSur) {
		this.invitationSurvey = invitationSurvey;
		this.updateSur = updateSur;
		removeAllComponents();
		buildComponent();
	}

	@Override
	public void buildComponent() {

		CustomLayout custom = new CustomLayout("custom/sidebarComponent");
		addComponent(custom);
		
		if(sessionHelper.isUserSessionSet() == false) {
			login = new LoginFormElement(this);
			
			custom.addComponent(textHelper.boxTitle(TM.get("loginbox.title")), "title");
			
			VerticalLayout boxContent = new VerticalLayout();
			boxContent.addComponent(textHelper.p(TM.get("loginbox.desc")));
			boxContent.addComponent(login);
			custom.addComponent(boxContent, "content");
		} else {
			custom.addComponent(textHelper.boxTitle(TM.get("loginbox.title")), "title");
			
			VerticalLayout boxContent = new VerticalLayout();
			boxContent.addComponent(textHelper.p(TM.get("loginbox.loggedin")));
			Button dashBoard = new Button(TM.get("loginbox.dashboard"));
			
			dashBoard.addListener(new ClickListener() {
				public void buttonClick(ClickEvent event) {
					urlLib.setPage("Dashboard");
				}
			});
			dashBoard.setIcon(Config.ICON_GOTO);
			
			boxContent.addComponent(dashBoard);
			
			custom.addComponent(boxContent, "content");
		}
	}

	public void setUsername(String email) {
		login.setUsername(email);
	}
	
	
}
